package classes.view.component
{
	import classes.controller.DAOSendFlash;
	import classes.controller.EClick;
	import classes.controller.EDataObject;
	
	import com.greensock.TweenMax;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.external.ExternalInterface;
	
	public class ListContainer extends Sprite
	{
		private var _listsIn:Sprite;
		
		private var _lists:Array;
		private var _list_x:Array = [20, 273, 525,  20, 273, 525];
		private var _list_y:Array = [ 9,   9,   9, 169, 169, 169];
		
		public function ListContainer()
		{
			super();
			setLayOut();
			
		}
		private function setLayOut():void
		{
			this._listsIn	= this.getChildByName('lists_mc')	as Sprite;
			this._lists 	= new Array(); 
		}
		
		
		public function set sortNum($sortNum:int):void
		{
			if(_lists !=null){
				for(var i:int = 0 ; i < _lists.length ; i++){
					_lists[i].sortNum = $sortNum;
				}
			}
		}
		public function set page($page:int):void
		{
			if(_lists !=null){
				for(var i:int = 0 ; i < _lists.length ; i++){
					_lists[i].page = $page;
				}
			}
		}
		
		
		public function set listOn($list:Array):void
		{
			
			resetList();
			if(_lists == null) this._lists 	= new Array(); 
			for(var i:int = 0 ; i < $list.length ; i++)
			{
				this._lists[i] 			= new ListObject();
				this._lists[i].setListObj(  $list[i].roomID,
											$list[i].question, 
											$list[i].sb_name,
											$list[i].title, 
											$list[i].dbName,
											$list[i].joinnow, 
											$list[i].joinmax,
											$list[i].state,
											$list[i].secret);

				this._lists[i].x			= _list_x[i];
				this._lists[i].y			= _list_y[i];
				
				this._lists[i].addEventListener(EClick.EVENT_CLICK,	onClickList);
				
				this._listsIn.addChild(this._lists[i]);
				
			}
		}
		
		private function onClickList(e:EClick):void
		{
			dispatchEvent(new EDataObject(['clickListObj'], EDataObject.EVENT_DATAOBJECT));
		}
		
		public function resetList():void
		{
			if(_lists != null){
				if(_lists.length > 0 ){
					while (this._listsIn.numChildren > 0) {
						this._listsIn.removeChildAt(0);
						_lists[_listsIn.numChildren].removeEventListener(EClick.EVENT_CLICK,	onClickList);
					}
					_lists.splice(0, _lists.length-1);
				}
				_lists = null;
			}
		}
	}
}